<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <title>商家列表</title>
    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>
    <link href="../../resource/css/font-awesome.min.css?v=4.4.0" rel="stylesheet"
          th:href="@{/resource/css/font-awesome.min.css?v=4.4.0}"/>
    <!-- Morris -->
    <link href="../../resource/css/animate.min.css" rel="stylesheet" th:href="@{/resource/css/animate.min.css}"/>

    <link href="../../resource/css/style.min.css?v=4.0.0" rel="stylesheet"
          th:href="@{/resource/css/style.min.css?v=4.0.0}"/>
    <link href="../../resource/hotui/css/hotui.style.override.css"
          rel="stylesheet" th:href="@{/resource/hotui/css/hotui.style.override.css}"/>
    <link href="../../resource/css/style-diy.css?v=4.0.0" rel="stylesheet"
          th:href="@{/resource/css/style-diy.css?v=4.0.0}"/>
    <link href="../../resource/hotui/js/plugins/datetimepick/css/daterangepicker.css"
          rel="stylesheet" th:href="@{/resource/hotui/js/plugins/datetimepick/css/daterangepicker.css}"/>
    <style>
        /*.daterangepicker {*/
        /*    z-index: 999999999 !important;*/
        /*}*/
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!--search-->
    <form class="search-panel" id="searchForm" method="get" role="form" th:object="${condition}">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="form-inline">
                            <input name="pageIndex" th:value="${pageIndex}" type="hidden"/>
                            <input type="hidden" th:value="${condition.status}" name="status"/>
                            <input type="hidden" th:value="${dataType}" name="dataType"/>

                            <div class="form-inline">
                                <div class="form-group m-r-sm">
                                    <label class=" control-label" for="keyword">关键字：</label>
                                    <input class="form-control input-sm mb10" id="keyword" name="keyword"
                                           placeholder="关键字"
                                           style="width: 156px;" th:value="*{keyword}" type="text"/>
                                </div>
                                <div class="form-group m-r-sm">
                                    <label class=" control-label" for="createTimePick">创建时间：</label>
                                    <input class="form-control input-sm mb10 data-range-pick" end-element="#endTime"
                                           id="createTimePick"
                                           placeholder="开始时间-结束时间" readonly
                                           start-element="#beginTime" style="width: 377px;" type="text"/>
                                    <input id="beginTime" name="beginTime" th:value="*{beginTime}" type="hidden"/>
                                    <input id="endTime" name="endTime" th:value="*{endTime}" type="hidden"/>
                                </div>
                                <div class="form-group m-r-sm">
                                    <button class="btn btn-primary btn-sm m-b-none searchBtn"
                                            onclick="listHandler.search(1)"
                                            type="button">筛选
                                    </button>
                                    <button class="btn btn-primary btn-sm m-b-none" onclick="listHandler.searchAll()"
                                            type="button">显示全部
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--search-->


    <!--list-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div class="tabs-container">
                    <!--                    <ul class="nav nav-tabs">-->
                    <!--                        <li class="active" th:class="${dataType==1?'active':''}">-->
                    <!--                            <a th:href="@{/merchant/list?dataType=1}">商家列表</a>-->
                    <!--                        </li>-->
                    <!--                        <li th:class="${dataType==0?'active':''}">-->
                    <!--                            <a th:href="@{/merchant/list?dataType=0}">审核列表</a>-->
                    <!--                        </li>-->
                    <!--                    </ul>-->
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body table-responsive">
                                <table class="table table-bordered table-hover table-center">
                                    <thead>
                                    <tr>
                                        <th>店铺ID/商户ID</th>
                                        <th>账号</th>
                                        <th>LOGO</th>
                                        <th>名称</th>
                                        <th>微信号</th>
                                        <th>联系方式</th>
                                        <th>主营类目</th>
                                        <th>货款</th>
                                        <th>时间</th>
                                        <th width="150">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr th:each="item,stat:${list}">
                                        <td th:text="${item.merchantId}"></td>
                                        <td th:text="${item.user.mobile}"></td>
                                        <td>
                                            <img style="border-radius: 10px;" alt="" height="50" src=""
                                                 th:src="${item.data.avatar+'?x-oss-process=image/resize,l_200'}"
                                                 width="50">
                                        </td>
                                        <td th:text="${item.data.title}"></td>
                                        <td th:text="${item.data.wechatAccount}"></td>
                                        <td th:text="${item.data.contactWay}"></td>
                                        <td>
                                            <span th:if="${item.data.mainCategory!=null}"
                                                  th:text="${@categoryService.getRootCategory(item.data.mainCategory.catId).getCatName()}"></span>/
                                            <span th:if="${item.data.mainCategory!=null}"
                                                  th:text="${item.data.mainCategory.catName}"></span>
                                        </td>
                                        <td>
                                            <span th:text="${item.balance}"></span>
                                            <br>
                                            <span class="color-danger">待入账：<span
                                                    th:text="${item.balanceInFuture}"></span></span>
                                        </td>
                                        <td th:text="${#temporals.format(item.createTime,'yyyy-MM-dd HH:mm:ss')}"></td>
                                        <td style="text-align: center">
                                            <button class="btn btn-default btn-xs m-b-none"
                                                    th:onclick="listHandler.detail([[${item.merchantId}]])"
                                                    type="button">查看
                                            </button>
                                            <button class="btn btn-primary btn-xs m-b-none"
                                                    th:if="${dataType==0&&item.auditStatus.code==0}"
                                                    th:onclick="listHandler.audit([[${item.merchantId}]])"
                                                    type="button">审核
                                            </button>
                                            <button class="btn btn-danger btn-xs m-b-none"
                                                    th:if="${dataType==1&&item.auditStatus.code==1}"
                                                    th:onclick="listHandler.resetPasswd([[${item.merchantId}]])"
                                                    type="button">重置密码
                                            </button>
                                            <th:block th:if="${dataType==1&&item.auditStatus.code==1}">
                                                <button class="btn btn-success btn-xs m-b-none"
                                                        th:onclick="listHandler.toggleContactStatus([[${item.merchantId}]])"
                                                        type="button" th:text="${item.enableContact?'关闭客服':'开启客服'}">开启客服
                                                </button>

                                                <button class="btn btn-primary btn-xs m-b-none"
                                                        th:onclick="listHandler.setRate([[${item.merchantId}]])"
                                                        type="button">抽成比例
                                                </button>


                                            </th:block>
                                            <button class="btn btn-primary btn-xs m-b-none"
                                                    th:if="${dataType==1&&item.auditStatus.code==1}"
                                                    th:onclick="listHandler.toShowCate([[${item.merchantId}]])"
                                                    type="button">修改主营类目
                                            </button>
                                        </td>

                                    </tr>
                                    </tbody>
                                </table>
                                <p style="float: left; margin: 20px 0;">
                                    共<span th:text="${totalRecords}"></span>条记录，当前第<span th:text="${pageIndex}"></span>/<span
                                        th:text="${totalPages==0?1:totalPages}"></span>，每页20条记录
                                </p>
                                <ul class="pagination pagination-split" style="float: right;">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script id="sel_merchant_cate_modal" type="text/html">
    <div class="form-horizontal" style="width: 500px;">
        <input type="hidden" id="merchantId"/>
        <div class="form-group form-inline">
            <label class="col-sm-3 control-label">主营类目</label>
            <div class="col-sm-8 jsChainSelect">
                                <span>
                                    <select class="form-control first">
                                        <option value="">请选择</option>
                                    </select>
                                </span>
                <span style="display:none;">
                                <select class="form-control second" id="catId" name="catId">
                                </select>
                                </span>
            </div>
        </div>
    </div>
</script>


<!--基础框架js-->
<script src="../../resource/js/jquery.min2.2.4.js?v=2.1.4" th:src="@{/resource/js/jquery.min2.2.4.js?v=2.1.4}"></script>
<script src="../../resource/js/bootstrap.min.js?v=3.3.5" th:src="@{/resource/js/bootstrap.min.js?v=3.3.5}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js}"
></script>
<script src="../../resource/lib/moment.min.js" th:src="@{/resource/lib/moment.min.js}"></script>
<script src="../../resource/hotui/js/plugins/datetimepick/js/daterangepicker.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/daterangepicker.js}"></script>
<script src="/resource/lib/jquery-chain-select/jquery.chainSelect.js?1.0"></script>
<script th:inline="javascript" type="text/javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  1;
    const pageUri = /*[[@{/merchant/list}]]*/  "";
    const detailUri = /*[[@{/merchant/detail}]]*/  "";
    const auditUri = /*[[@{/merchant/audit}]]*/  "";
    const apiUri = /*[[@{/merchant}]]*/  "";
    const toMerchantMainCateUri = /*[[@{/merchant/modify/mainCategory}]]*/  "";
</script>
<script>
    let modifyMerchantCate = $('#sel_merchant_cate_modal').modal('修改商家主营类目', function () {
        hot.ajax(toMerchantMainCateUri, {
            categoryId: $("#catId").val(),
            merchantId: $("#merchantId").val()
        }, function (apiResult) {
            if (apiResult.resultCode === 2000) {
                hot.tip.success("修改成功");
                modifyMerchantCate.hide();
                location.reload();
            } else {
                hot.tip.error(apiResult.resultMsg);
            }
        }, function () {
        }, "post")
    });
    $(function () {
        //初始化分页
        var pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            listHandler.search(p);
        });
        $(document).keyup(function (event) {
            if (event.keyCode === 13) {
                $(".searchBtn").trigger("click");
            }
        });
    });
    let listHandler = {
        search: function (pageIndex) {
            $("input[name=pageIndex]").val(pageIndex);
            $("#searchForm").submit();
        },
        searchAll: function () {
            window.location.href = pageUri + "?dataType=" + $("input[name=dataType]").val();
        },
        detail: function (dataId) {
            hot.newTab(detailUri + "?id=" + dataId, "查看商户信息-" + dataId);
        },
        audit(dataId) {
            hot.iframeModal(auditUri + "?id=" + dataId, "580px", "320px", "审核", {
                end: function (obj) {
                    window.location.reload();
                }
            });
        },
        resetPasswd: function (merchantId) {
            hot.confirm("确定要重置密码，默认密码为：123456", function () {
                hot.ajax(apiUri + "/resetPass", {
                    merchantId: merchantId
                }, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("重置成功", function () {
                            window.location.reload();
                        });
                    } else {
                        hot.tip.error(apiResult.resultMsg);
                    }
                }, function () {
                }, "post", 300);
            })
        },
        initCategory: function () {
            // var catTree = $('#hidCatTree').val();
            var first = null, second = null, third = null;
            var catSelect = $('.jsChainSelect').chainSelect({
                url: '/category/getList',
                first: first,
                second: second,
                third: null,
                onInitComplete: function () {
                }
            });
        },
        toShowCate(id) {
            modifyMerchantCate.show(function () {
                $("#merchantId").val(id);
                listHandler.initCategory();
            });
        },
        toggleContactStatus(id) {
            hot.ajax(apiUri + "/toggleContact", {
                merchantId: id
            }, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    hot.tip.success("操作成功", function () {
                        window.location.reload();
                    }, 100);
                } else {
                    hot.tip.error(apiResult.resultMsg);
                }
            }, function () {
            }, "get", 300);
        },
        setRate(merchantId) {
            hot.iframeModal(apiUri + "/rate/edit?merchantId=" + merchantId, "650px", "400px", '设置抽成比例');
        }
    }
</script>
</body>
</html>